<?php

namespace App\Models;

class PoolModel
{
    /**
     * 获取最新一条
     * return Array
     * */
    public static function getPoolInside($conn){
        $querySql="SELECT `id`,`bonus`,`devote`,`user`,`sell`,`time` FROM `pool` WHERE  `state` = 1 order by `id` desc limit 1";
        return $conn->readConn($querySql);
    }
    /**
     * 更新奖励
     * entry conn $PoolExample
     * return int
     * */
    public static function upPool($conn,$bonus,$devote,$PoolExample){
        $sql = "UPDATE `pool` SET `bonus` = `bonus` + $bonus,`devote` = `devote` + $devote WHERE `id` = $PoolExample->id and `bonus` = $PoolExample->bonus and `devote` = $PoolExample->devote";
        return $conn->executeConn($sql);
    }
    /**
     * 采购手续费写入
     * entry conn $PoolExample
     * return int
     * */
    public static function upPoolUser($conn,$user,$PoolExample){
        $sql = "UPDATE `pool` SET `user` = `user` + $user WHERE `id` = $PoolExample->id and `user` = $PoolExample->user";
        return $conn->executeConn($sql);
    }
    /**
     * 编辑奖池信息
     * entry $WithdrawExample
     * return int
     * */
    public static function editPoolInside($conn,$PoolExample){
        $joinSql="";
        if($PoolExample->prec !=null){
            $joinSql.=" `prec` = '$PoolExample->prec',";
        }
        if($PoolExample->state !=null){
            $joinSql.=" `state` = '$PoolExample->state',";
        }
        if($joinSql !=null){
            $innerJoin = rtrim($joinSql,",");
            $upUserSql="UPDATE  `pool` SET $innerJoin WHERE `id` =$PoolExample->id";
            return $conn->executeConn($upUserSql);
        }
    }
}